<!-- 搜索项目 -->
<template>
  <h-select-input-popup
    ref="hSelectInputPopup"
    v-model="val"
    v-bind="$attrs"
    v-on="$listeners"
    :params="queryParams"
    :keywords.sync="keywords"
    :getList="getList"
    @getDetail="getDetail"
    @change="$emit('change', $event)"
  >
    <template v-slot:default="{ item }">
      <view class="project-item">
        <view class="option">
          <view class="lf">档案编号</view>
          <view class="rl">{{ item.billNo }}</view>
        </view>
        <view class="option">
          <view class="lf">档案大类</view>
          <view class="rl">{{ item.docBigCategory_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">档案小类</view>
          <view class="rl">{{ item.docSmallCategory_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">档案所属团队</view>
          <view class="rl">{{ item.teamId_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">密级</view>
          <view class="rl">{{ item.classification_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">凭证号范围</view>
          <view class="rl">{{ item.voucherNumberRange }}</view>
        </view>
        <view class="option">
          <view class="lf">凭证数总册数</view>
          <view class="rl">{{ item.totalNumber }}</view>
        </view>
        <view class="option">
          <view class="lf">档案室位置</view>
          <view class="rl">{{ item.docAddress }}</view>
        </view>
      </view>
    </template>
  </h-select-input-popup>
</template>

<script>
import { erpOaDocBaseInfoList, erpOaDocBaseInfoById } from '@/api/index.js'

export default {
  name: 'HSelectOadocBaseInputPopup',
  data() {
    return {
      getList: erpOaDocBaseInfoList,
      params: {
        column: 'createTime',
        order: 'desc',
        pageNo: 1,
        pageSize: 10,
        docBigCategory: '',
        docSmallCategory: '',
        field: 'id,,,billNo,docBigCategory_dictText,docSmallCategory_dictText,teamId_dictText,classification_dictText,voucherNumberRange,totalNumber,docAddress',
      },
      keywords: '',
    }
  },
  model: {
    prop: 'value',
    event: 'input',
  },
  props: {
    value: {
      type: [String, Number, Array],
      default: null,
    },
    muitFlag: {
      type: Boolean,
      default: false,
    },
    docBigCategory: {
      type: String,
      default: ''
    },
    docSmallCategory: {
      type: String,
      default: ''
    }
  },
  computed: {
    val: {
      get() {
        return this.value
      },
      set() {
        this.$emit('input', this.value)
      },
    },
    queryParams() {
      const params = {
        ...this.params,
      }
      if (this.keywords) {
        params.billNo = '*' + this.keywords + '*'
      }
      return params
    },
  },
  watch: {
    docBigCategory: {
      handler(big) {
        this.$set(this.params, 'docBigCategory', big)
      },
      deep: true,
    },
    docSmallCategory: {
      handler(small) {
        this.$set(this.params, 'docSmallCategory', small)
      },
      deep: true,
    },
  },
  methods: {
    // 获取详情
    getDetail(value) {
      erpOaDocBaseInfoById({ id: value }).then((res) => {
        if (res.success) {
          this.$refs.hSelectInputPopup.title = res.result.billNo
          this.$emit('select', {
            data: res.result,
            id: value,
          })
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>

// 按钮
.btn {
  position: fixed;
  bottom: 20rpx;
  width: 95%;
}
</style>
